&self.source_id
}
+ pub fn get_kind(&self) -> Kind { self.kind }
+
pub fn kind(mut self, kind: Kind) -> Dependency {
self.kind = kind;
self
use core::source::Source;
use core::{Package, MultiShell, SourceId};
+use core::dependency::Kind;
use core::manifest::ManifestMetadata;
use ops;
use sources::{PathSource, RegistrySource};
features: dep.get_features().to_vec(),
version_req: dep.get_version_req().to_string(),
target: dep.get_only_for_platform().map(|s| s.to_string()),
+ kind: match dep.get_kind() {
+ Kind::Normal => "normal",
+ Kind::Build => "build",
+ Kind::Development => "dev",
+ }.to_string(),
}
}).collect::<Vec<NewCrateDependency>>();
let manifest = pkg.get_manifest();
use url::Url;
use core::{Source, SourceId, PackageId, Package, Summary, Registry};
-use core::Dependency;
+use core::dependency::{Dependency, Kind};
use sources::{PathSource, git};
use util::{CargoResult, Config, internal, ChainError, ToUrl, human};
use util::{hex, Require, Sha256};
optional: bool,
default_features: bool,
target: Option<String>,
+ kind: Option<String>,
}
impl<'a, 'b> RegistrySource<'a, 'b> {
fn parse_registry_dependency(&self, dep: RegistryDependency)
-> CargoResult<Dependency> {
let RegistryDependency {
- name, req, features, optional, default_features, target
+ name, req, features, optional, default_features, target, kind
} = dep;
let dep = try!(Dependency::parse(name.as_slice(), Some(req.as_slice()),
&self.source_id));
+ let kind = match kind.as_ref().map(|s| s.as_slice()).unwrap_or("") {
+ "dev" => Kind::Development,
+ "build" => Kind::Build,
+ _ => Kind::Normal,
+ };
Ok(dep.optional(optional)
.default_features(default_features)
.features(features)
- .only_for_platform(target))
+ .only_for_platform(target)
+ .kind(kind))
}
/// Actually perform network operations to update the registry
pub features: Vec<String>,
pub version_req: String,
pub target: Option<String>,
+ pub kind: String,
}
#[deriving(Decodable)]
.build();
}
-pub fn mock_archive(name: &str, version: &str, deps: &[(&str, &str)]) {
+pub fn mock_archive(name: &str, version: &str, deps: &[(&str, &str, &str)]) {
let mut manifest = format!(r#"
[package]
name = "{}"
version = "{}"
authors = []
"#, name, version);
- for &(dep, req) in deps.iter() {
+ for &(dep, req, kind) in deps.iter() {
manifest.push_str(format!(r#"
- [dependencies.{}]
+ [{}dependencies.{}]
version = "{}"
- "#, dep, req).as_slice());
+ "#, match kind {
+ "build" => "build-",
+ "dev" => "dev-",
+ _ => ""
+ }, dep, req).as_slice());
}
let p = project(name)
.file("Cargo.toml", manifest.as_slice())
dl_path().join(name).join(version).join("download")
}
-pub fn mock_pkg(name: &str, version: &str, deps: &[(&str, &str)]) {
+pub fn mock_pkg(name: &str, version: &str, deps: &[(&str, &str, &str)]) {
mock_pkg_yank(name, version, deps, false)
}
-pub fn mock_pkg_yank(name: &str, version: &str, deps: &[(&str, &str)],
+pub fn mock_pkg_yank(name: &str, version: &str, deps: &[(&str, &str, &str)],
yanked: bool) {
mock_archive(name, version, deps);
let c = File::open(&mock_archive_dst(name, version)).read_to_end().unwrap();
&[&parent]).unwrap();
}
-pub fn pkg(name: &str, vers: &str, deps: &[(&str, &str)], cksum: &str,
+pub fn pkg(name: &str, vers: &str, deps: &[(&str, &str, &str)], cksum: &str,
yanked: bool) -> String {
- let deps = deps.iter().map(|&(a, b)| dep(a, b)).collect::<Vec<String>>();
+ let deps = deps.iter().map(|&(a, b, c)| dep(a, b, c)).collect::<Vec<String>>();
format!("{{\"name\":\"{}\",\"vers\":\"{}\",\
\"deps\":{},\"cksum\":\"{}\",\"features\":{{}},\
\"yanked\":{}}}",
name, vers, deps, cksum, yanked)
}
-pub fn dep(name: &str, req: &str) -> String {
+pub fn dep(name: &str, req: &str, kind: &str) -> String {
format!("{{\"name\":\"{}\",\
\"req\":\"{}\",\
\"features\":[],\
\"default_features\":false,\
\"target\":null,\
- \"optional\":false}}", name, req)
+ \"optional\":false,\
+ \"kind\":\"{}\"}}", name, req, kind)
}
pub fn cksum(s: &[u8]) -> String {
.file("src/main.rs", "fn main() {}");
r::mock_pkg("baz", "0.0.1", &[]);
- r::mock_pkg("bar", "0.0.1", &[("baz", "*")]);
+ r::mock_pkg("bar", "0.0.1", &[("baz", "*", "normal")]);
assert_that(p.cargo_process("build"),
execs().with_status(0).with_stdout(format!("\
p.build();
r::mock_pkg("baz", "0.0.1", &[]);
- r::mock_pkg("bar", "0.0.1", &[("baz", "*")]);
+ r::mock_pkg("bar", "0.0.1", &[("baz", "*", "normal")]);
assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(0).with_stdout(format!("\
p.root().move_into_the_past().unwrap();
r::mock_pkg("baz", "0.0.2", &[]);
- r::mock_pkg("bar", "0.0.2", &[("baz", "*")]);
+ r::mock_pkg("bar", "0.0.2", &[("baz", "*", "normal")]);
assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(0).with_stdout(""));
r::mock_pkg("baz", "0.0.1", &[]);
r::mock_pkg_yank("baz", "0.0.2", &[], true);
- r::mock_pkg("bar", "0.0.1", &[("baz", "*")]);
- r::mock_pkg_yank("bar", "0.0.2", &[("baz", "*")], true);
+ r::mock_pkg("bar", "0.0.1", &[("baz", "*", "normal")]);
+ r::mock_pkg_yank("bar", "0.0.2", &[("baz", "*", "normal")], true);
assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(0).with_stdout(format!("\
r::mock_pkg("baz", "0.0.1", &[]);
r::mock_pkg_yank("baz", "0.0.2", &[], true);
- r::mock_pkg("bar", "0.0.1", &[("baz", "=0.0.2")]);
+ r::mock_pkg("bar", "0.0.1", &[("baz", "=0.0.2", "normal")]);
assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(101).with_stderr("\
", downloading = DOWNLOADING, compiling = COMPILING,
dir = p.url()).as_slice()));
})
+
+test!(dev_dependency_not_used {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [project]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+
+ [dependencies]
+ bar = "*"
+ "#)
+ .file("src/main.rs", "fn main() {}");
+ p.build();
+
+ r::mock_pkg("baz", "0.0.1", &[]);
+ r::mock_pkg("bar", "0.0.1", &[("baz", "*", "dev")]);
+
+ assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
+ execs().with_status(0).with_stdout(format!("\
+{updating} registry `[..]`
+{downloading} [..] v0.0.1 (registry file://[..])
+{compiling} bar v0.0.1 (registry file://[..])
+{compiling} foo v0.0.1 ({dir})
+", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING,
+ dir = p.url()).as_slice()));
+})